﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;
using Chinaer.Core.BaseCore.Extensions;

namespace Chinaer.Bll
{
    public class ShangJiaIsReadZhongXinGongGao : Repository, Chinaer.IBll.IShangJiaIsReadZhongXinGongGao
    {
        Chinaer.IDao.IShangJiaIsReadZhongXinGongGaoDAO shangJiaIsReadDAO = new Chinaer.Dao.ShangJiaIsReadZhongXingGongGaoDAO();
        public JsonResult GetShangJiaIsReadZhongXinGongGao(string shangJiaID, string zhongXinGongGaoID)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = shangJiaIsReadDAO.GetShangJiaIsReadStatue(zhongXinGongGaoID, shangJiaID);
            return jsonResult;
        }

        public JsonResult Add(DTO.ShangJiaIsReadZhongXinGongGaoDTO t)
        {
            JsonResult jsonResult = new JsonResult();
            if (t.CheckIsNull().Success == false)
            {
                jsonResult.Success = false;
                jsonResult.LoginStatus = Chinaer.Core.BaseCore.LoginStatus.EntityIsNull;
                jsonResult.ErrorMessage = jsonResult.LoginStatus.ToDescription();
                return jsonResult;
            }
            //表示已经存在 不需要添加数据
            if (GetShangJiaIsReadZhongXinGongGao(t.ShangJiaID, t.ZhongXinGongGaoID).Success==true)
            {
                jsonResult.Success = true;
                jsonResult.LoginStatus = Chinaer.Core.BaseCore.LoginStatus.Success;
                jsonResult.ErrorMessage = "";
                return jsonResult;
            }


            Model.Entities.Model_ShangJiaIsReadZhongXinTongGao model_ShangJiaIsReadZhongXinGongGao = new Model.Entities.Model_ShangJiaIsReadZhongXinTongGao();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_ShangJiaIsReadZhongXinGongGao);
            if (string.IsNullOrEmpty(model_ShangJiaIsReadZhongXinGongGao.ID) || model_ShangJiaIsReadZhongXinGongGao.ID.Trim() == "")
            {
                model_ShangJiaIsReadZhongXinGongGao.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = shangJiaIsReadDAO.Add(model_ShangJiaIsReadZhongXinGongGao);
            return jsonResult;
        }

        public JsonResult Delete(DTO.ShangJiaIsReadZhongXinGongGaoDTO t)
        {
            JsonResult jsonResult = new JsonResult();
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            Model.Entities.Model_ShangJiaIsReadZhongXinTongGao model_ShangJiaIsReadZhongXinGongGao = new Model.Entities.Model_ShangJiaIsReadZhongXinTongGao();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_ShangJiaIsReadZhongXinGongGao);
            jsonResult.Success = shangJiaIsReadDAO.Delete(model_ShangJiaIsReadZhongXinGongGao);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = shangJiaIsReadDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.ShangJiaIsReadZhongXinGongGaoDTO t)
        {
            JsonResult jsonResult = new JsonResult();
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            Model.Entities.Model_ShangJiaIsReadZhongXinTongGao model_ShangJiaIsReadZhongXinGongGao = new Model.Entities.Model_ShangJiaIsReadZhongXinTongGao();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_ShangJiaIsReadZhongXinGongGao);
            if (model_ShangJiaIsReadZhongXinGongGao != null)
            {
                model_ShangJiaIsReadZhongXinGongGao.IsRead = true;
            }
            jsonResult.Success = shangJiaIsReadDAO.Update(model_ShangJiaIsReadZhongXinGongGao);
            return jsonResult;
        }

        public DTO.ShangJiaIsReadZhongXinGongGaoDTO GetByID(string id)
        {
            Model.Entities.Model_ShangJiaIsReadZhongXinTongGao model_ShangJiaIsReadZhongXinGongGao = shangJiaIsReadDAO.GetByID(id);
            DTO.ShangJiaIsReadZhongXinGongGaoDTO shangJiaIsReadZhongXinGongGao = new DTO.ShangJiaIsReadZhongXinGongGaoDTO();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_ShangJiaIsReadZhongXinGongGao, shangJiaIsReadZhongXinGongGao);
            return shangJiaIsReadZhongXinGongGao;
        }       
    }
}
